<style>
    @media screen and (max-width: 500px) {
        .layui-layer.layui-layer-page {
            width: 100% !important;
            overflow-x: scroll !important;
            left: 0 !important;
        }
        .layui-layer-title {
            width: 100% !important;
            box-sizing: border-box;
        }
        .layui-layer-content {
            width: 100% !important;
        }
    }
</style>
<form class="layui-form seller-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">时间范围：</label>
            <div class="layui-input-inline seller-inline-3">
                <input class="layui-input" autocomplete="off" placeholder="开始日期" name="start" id="start">
            </div>
            <div class="layui-input-inline seller-inline-3">
                <input class="layui-input" autocomplete="off" placeholder="截止日期" name="end" id="end">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">状态：</label>
            <div class="layui-input-inline seller-inline-3">
                <select name="status" lay-verify="">
                    <option value=""></option>
                    <option value="0">禁用</option>
                    <option value="1">启用</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">关键字：</label>
            <div class="layui-input-inline seller-inline-3">
                <input type="text" name="search" lay-verify="title" placeholder="ID/名称" autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-submit lay-filter="user-search"><i
                    class="iconfont icon-chaxun"></i>筛选</button>
        </div>
    </div>
</form>
<div style="margin-top: 10px;">
    <button type="button" class="layui-btn layui-btn-sm add">添加</button>
</div>
<div class="table-body">
    <table id="userTable" lay-filter="test"></table>
</div>

<script type="text/html" id="option">
	<a class="layui-btn layui-btn-xs" lay-event='edit'>编辑</a>
	<a class="layui-btn layui-btn-xs" lay-event='del'>删除</a>
</script>

<script src="__STATIC_JS__jquery.form.js" type="text/javascript" charset="utf-8"></script>
<script>
    var table, window_box;
    layui.use(['form', 'layedit', 'laydate', 'table','util'], function () {
    	var util=layui.util,table=layui.table,laydate=layui.laydate;
            layui.table.render({
            elem: '#userTable',
            method:'post',
            url: "{:url('sortlist')}",
            id: 'userTable',
            cols: [[
                { title: '操作', templet:'#option', align: 'center'},
                { field: 'id', title: 'ID', align: 'center'},
                { field: 'name', title: '名称',templet:function(d){
                    if(d.level==0){
                        return d.name;
                    }else if(d.level==1){
                        return '&nbsp;&nbsp;&nbsp;&nbsp;L'+d.name;
                    }
                }},
                { field: 'sort', title: '排序',align: 'center'},
                { field: 'status', title: '状态', align: 'center',templet:function(d){
                    if(d.status==0){
                        return '<span style="color: #FF5722;">禁用</span>';
                    }else{
                        return '<span style="color: #5FB878;">启用</span>';
                    }
                }},
                { field: 'ctime', title: '提交时间', align: 'center',templet:function(d){
                	return util.toDateString(d.ctime*1000);
                }}
            ]]
        });
        //搜索
        layui.form.on('submit(user-search)', function (data) {
            layui.table.reload('userTable', {
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
        table.on('tool(test)', function(obj){
        	if(obj.event=='edit'){
                layer.open({
                type:2,
                content:"{:url('addsort')}?id="+obj.data.id,
                area:['500px','400px'],
                });
        	}else if(obj.event=='del'){
                $.post("{:url('delsort')}",{id:obj.data.id},function(info){
                    if(info.code){
                        layer.msg(info.msg,{anim:0},function(){table.reload('userTable');});
                    }else{
                        layer.msg(info.msg);
                    }
                });
            }
        });
        laydate.render({
            elem:'#start',
            type:'datetime'
        });
        laydate.render({
            elem: '#end',
            type:'datetime'
        });
        $(".add").click(function(){
            layer.open({
                type:2,
                content:"{:url('addsort')}",
                area:['500px','400px'],
            });
        });
    });
</script>